@extends('admin.layout')
@section('title',$title)
@section('content')
	<div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                用户管理
                <small>用户管理添加页面</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 用户管理</a></li>
                <li class="active">用户添加</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <!-- left column -->
                <div class="col-md-12">
                    <!-- general form elements -->
                    <div class="box box-primary">
                        <div class="box-header with-border">
                            <h3 class="box-title">用户添加</h3>
                        </div><!-- /.box-header -->
                        <!-- form start -->
                        @if(session('error'))
                            <div class="alert alert-danger">
                                {{session('error')}}
                            </div>
                        @endif
                        @if (count($errors) > 0)
                            <div class="alert alert-danger">
                                <ul>
                                    @foreach ($errors->all() as $error)
                                        <li>{{ $error }}</li>
                                    @endforeach
                                </ul>
                            </div>
                        @endif
                        
                        <form role="form" action="/admin/user/insert" method="post" enctype="multipart/form-data">
                            {{ csrf_field() }}
                            <div class="box-body">
                                <div class="form-group">
                                    <label for="exampleInputEmail1">用户名</label>
                                    <input type="text" name="username" value="{{old('username')}}" class="form-control" id="exampleInputEmail1"
                                           placeholder="请输入6-18位的用户名" required onblur = "return get_user()">
                                    <span id="hwj_name" style="color:#f69;font-size:16px"></span>
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputPassword1">密码</label>
                                    <input type="password" name="password" class="form-control" id="exampleInputPassword1"
                                           placeholder="请输入8-16位密码" required>
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputPassword1">确认密码</label>
                                    <input type="password" name="repassword" class="form-control" id="exampleInputPassword1"
                                           placeholder="请确认密码" required>
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputPassword1">邮箱</label>
                                    <input type="email" value="{{old('email')}}" name="email" class="form-control" id="exampleInputPassword1"
                                           placeholder="请输入正确的邮箱" required>
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputPassword1">手机</label>
                                    <input type="text" name="phone" value="{{old('phone')}}" class="form-control" id="exampleInputPassword1"
                                           placeholder="请输入11位手机号" required>
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputFile">个人头像</label>
                                    <ul id="warp">
                                        <li style="list-style-type: none;">
                                            <img id="imgShow_WU_FILE_0" width="200" height="200" />
                                            <input type="file" id="up_img_WU_FILE_0" name="pic" required/>
                                        </li>
                                    </ul>
                                    <p class="help-block">请输入漂亮的图片</p>
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputEmail1">权限</label>
                                    <select class="form-control select2" style="width: 20%;" name="quanxian">
                                        <option>普通用户</option>
                                        <option>管理员</option>
                                    </select>
                                </div>
                            </div><!-- /.box-body -->

                            <div class="box-footer">
                                <button type="submit" class="btn btn-primary">添加</button>
                                <button type="reset" class="btn btn-danger">重置</button>
                            </div>
                        </form>
                    </div><!-- /.box -->

                   
                </div><!--/.col (left) -->

            </div>   <!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->
    <script type="text/javascript">
          function get_user()
          {
           $.ajaxSetup({
            headers: {
              'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
           });
            var username = $("input[name='username']").val();

            $.post('/admin/user/checkuser',{'username':username},function(msg){
                if(msg == 0)
                {
                    $('.btn-primary').removeAttr('disabled');
                    $('#hwj_name').html('');
                }else{
                    $('.btn-primary').attr('disabled','disabled');
                    $('#hwj_name').html(msg);
                }
                
            });
          }
       </script>
@endsection
